﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
    public partial class Form3: Form
    {
        public Form3()
        {
            InitializeComponent();
            this.WindowState = FormWindowState.Maximized;
            Onload();
        }
        string[] title = new string[] { 
             "Nan:急料批数=计划数",
             "Nv:急料批数=已收料数",
             "1:来料批数=计划总数",
             "2:来料批数=已收料数",
             "3:入库批数=已入库",
             "4:入库批数=待入库",
             "5:检验批数=合格数",
             "6:检验批数=不良数",
             "7:滞留待检验批数=昨天",
             "8:滞留待检验批数=昨天前"
            };

        public void BingTitle(string[] layoutStrings)
        {
          //  StringBuilder lyString = new StringBuilder();
          //  StringBuilder captionString = new StringBuilder();
          //  StringBuilder captionString2 = new StringBuilder();
          //  foreach (var a in layoutStrings)
          //  {
          //      lyString.AppendFormat(a.Substring(0, a.IndexOf("=")) + ",");
          //      captionString.AppendFormat(a.Substring(a.IndexOf("=") + 1, a.Length - a.IndexOf("=") - 1) + ",");
          //      captionString2.AppendFormat(a.Substring(a.IndexOf(":") + 1, (a.Length - a.IndexOf(":") + 1) - (a.Length - a.IndexOf("=") + 2)) + ",");
          //  }
          //  string[] columnName = lyString.ToString().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
          //  string[] columnName2 = captionString2.ToString().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
          //  string[] columnCaptions = captionString.ToString().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);


          //  System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle();
          //  dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;//211, 223, 240
          //  dataGridViewCellStyle2.BackColor = Color.Red;
          //  dataGridViewCellStyle2.Font = new System.Drawing.Font("宋体", 20F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));


          //  string f1 = null;
          //  string f2 = null;
          //  string f3 = null;
          //  TreeView tv = new TreeView();
          ////  s.Distinct().ToArray();
          //  foreach (string t1 in columnName2.Distinct().ToArray())
          //  {
          //      TreeNode tnSex = new TreeNode(t1);
               
          //      tv.Nodes.Add(tnSex);
          //      for (int i = 0; i < columnName.Length; i++)
          //      {
          //          string[] columnInfo = columnName[i].Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries);
          //          if (columnInfo.Length <= 0 || columnInfo.Length > 2)
          //              continue;
          //          if (columnInfo[1].Trim() == t1)
          //          {
          //              f1 = columnName[i].Substring(0, columnName[i].IndexOf(":"));
          //              f2 = columnName[i].Substring(columnName[i].IndexOf(":") + 1, columnName[i].Length - columnName[i].IndexOf(":") - 1);
          //              f3 = columnCaptions[i].Substring(columnCaptions[i].IndexOf(":") + 1, columnCaptions[i].Length - columnCaptions[i].IndexOf(":") - 1);
          //              DataGridViewTextBoxColumn tcNan = new DataGridViewTextBoxColumn();
          //              tcNan.HeaderText = f3;
          //              tcNan.Name = f1;
                      
          //              tcNan.Width = Screen.PrimaryScreen.Bounds.Width / 10;
                       
          //              tcNan.ReadOnly = true;
          //              dgv.Columns.Add(tcNan);
          //              TreeNode tnNan = new TreeNode(f3);
          //              tnSex.Nodes.Add(tnNan);
          //          }
          //      }
          //      tnSex.BackColor = Color.Red;
          //      tnSex.ForeColor = Color.Red;
          //  }
          //  dgv.ColumnTreeView = new TreeView[] { tv };
            //设置其他属性
           // dgv.AutoGenerateColumns = false;                                    //不自动增加列
            dgv.RowHeadersVisible = false;                                      //行头不可见
            dgv.AllowUserToAddRows = false;
            dgv.RowTemplate.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
            dgv.ColumnDeep = 2;
            dgv.CellHeight = pnlHeader.Height / 3;
            dgv.ColumnHeadersHeight = pnlHeader.Height;
            dgv.AllowUserToResizeRows = false;
            dgv.AllowUserToResizeColumns = false;
            dgv.RefreshAtHscroll = true;

        }

        public void Onload()
        {
            InitLableSie();
            BingTitle(title);
          
        }
        int cellHeight = 69;
        int Width=0;
        int Height=0;
        //控件的宽度
        int lwidth = 0;
        private void InitLableSie()
        {

            //屏幕分辩率宽度
            double swidth = Screen.PrimaryScreen.Bounds.Width;
            //窗体头初始宽度
            double fwidth = 1380;
           
          

            foreach (Control con in pnlHeader.Controls)
            {
                if (con != null)
                {
                    lwidth = Convert.ToInt32((con.Width / fwidth) * swidth);
                    con.Width = lwidth;
                }
            }
        }

    }
}

